package perl.lexical.classes;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Keyword extends TokenClass {

	
	public final static String IF = "if";
	public final static String ELSE = "else"; 
	public final static String FOR = "for"; 
	public final static String WHILE = "while";
	public final static String SUB = "sub"; 
	public final static String GOTO = "goto"; 
	public final static String NEXT = "next"; 
	public final static String LAST = "last";
	public final static String PRINT = "print"; 
	public final static String STDIN = "stdin"; 
	public final static String RETURN = "return";
	
	public final static String[] keywords = {IF, ELSE, FOR,GOTO, NEXT, LAST, PRINT, STDIN, SUB, RETURN, WHILE};
	
	
	@Override
	public Token generateToken(String lexem) {	
		
		 Pattern p;
		 Matcher m;

		 for(String keyword : keywords){
			 p = Pattern.compile("\\s*" + keyword + "|\\s*" + keyword + "[\\W\\s].*");
			 m = p.matcher(lexem);
			 
			 
			 if(m.matches()){
				 return new Token(className, keyword);
			 }
		 }
		return null;
	}
	

	public Keyword(){
		className = TokenClassEnum.KEYWORD;
	}
	
}
